@extends('index.user.index')
@section('navbar')
    <ol class="breadcrumb">
        <li><a href="{{url('/')}}">首页</a></li>
        <li><a href="{{url('/user')}}">用户中心</a></li>
        <li><a href="{{url('/user/items')}}">失物招领</a></li>
        <li class="active">发布失物招领</li>
    </ol>
@endsection
@section('user-content')
    <form class="form-horizontal" method="POST" action="{{ url('/user/add-item') }}">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="hidden" name="match_id" value="{{$request->input('match_id')}}">

        <div class="form-group">
            <label class="col-sm-2 control-label">类型</label>

            <div class="col-sm-2">
                <select name="type" class="selectpicker" data-width="100">
                    <option></option>
                    @foreach($types as $type => $name)
                        <option value="{{$type}}" <?=$request->input('type') == $type ? 'selected' : ''?>>{{$name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">名称</label>

            <div class="col-sm-4">
                <input type="text" class="form-control" name="name" placeholder="名称"
                       value="{{$request->input('name')}}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">时间</label>

            <div class="col-sm-3">
                <input type="text" size="19" class="form-control form_datetime" name="time" placeholder="时间"
                       data-datepicker readonly value="{{$request->input('time')}}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">地点</label>

            <div class="col-sm-2">
                <select name="province_id" class="selectpicker" data-width="150" data-toggle="selectpicker"
                        data-nextselect="#city_id" data-refurl="{{url('api/area/areas?id=')}}{value}"
                        data-type="get">
                    <option></option>
                    @foreach($provinces as $province)
                        <option value="{{$province->id}}" <?=$request->input('province_id') == $province->id ? 'selected' : ''?>>{{$province->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-sm-2">
                <select name="city_id" id="city_id" class="selectpicker" data-width="150"
                        data-toggle="selectpicker"
                        data-nextselect="#district_id"
                        data-refurl="{{url('api/area/areas?id=')}}{value}"
                        data-type="get">
                    <option></option>
                    @foreach($cities as $city)
                        <option value="{{$city->id}}" <?=$request->input('city_id') == $city->id ? 'selected' : ''?>>{{$city->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-sm-2">
                <select name="district_id" id="district_id" class="selectpicker" data-width="150">
                    <option></option>
                    @foreach($districts as $district)
                        <option value="{{$district->id}}" <?=$request->input('district_id') == $district->id ? 'selected' : ''?>>{{$district->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"></label>

            <div class="col-sm-9">
                <input type="text" class="form-control" name="place" placeholder="详细地址"
                       value="{{$request->input('place')}}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">分类</label>

            <div class="col-sm-2">
                <select name="p_catalog_id" class="selectpicker" data-width="150" data-toggle="selectpicker"
                        data-nextselect="#catalog_id"
                        data-refurl="{{url('api/catalog/catalogs?id=')}}{value}"
                        data-type="get">
                    <option></option>
                    @foreach($p_catalogs as $p_catalog)
                        <option value="{{$p_catalog->id}}" <?=$request->input('p_catalog_id') == $p_catalog->id ? 'selected' : ''?>>{{$p_catalog->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-sm-2">
                <select name="catalog_id" id="catalog_id" class="selectpicker" data-width="150">
                    <option></option>
                    @foreach($catalogs as $catalog)
                        <option value="{{$catalog->id}}" <?=$request->input('catalog_id') == $catalog->id ? 'selected' : ''?>>{{$catalog->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">酬金</label>

            <div class="col-sm-2">
                <input type="text" class="form-control" name="wanted_fee" placeholder="酬金"
                       value="{{$request->input('wanted_fee')}}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">图片</label>

            <div class="col-sm-9">
                <input type="file" id="file" name="image" multiple data-min-file-count="1">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">详细描述</label>

            <div class="col-sm-9">
                <textarea class="form-control" name="describe" rows="6">{{$request->input('describe')}}</textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success radius">发布</button>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        $(function () {
            $(".form_datetime").datetimepicker({format: 'yyyy-mm-dd hh:ii:ss'});
            $('#file').fileinput({
                language: 'zh',
                uploadUrl: '/user/add-item-image',
                deleteUrl: '/user/delete-item-image',
                maxFileSize: 5000,
                maxFilesNum: 10,
                allowedFileExtensions : ['jpg', 'png','gif'],
                uploadExtraData: {'_token' : '{{ csrf_token() }}'}
            }).on('fileuploaded', function(event, data){
                $that = $(this);
                $.each(data.files, function(k, v){
                    $that.after('<input type="hidden" name="item_images[]" value="' + v.name + '">');
                });
            }).on('filecleared', function(){
                $(this).siblings('input').remove();
            });
        });
    </script>
@endsection